import React, { useEffect, useRef, useState, lazy, useImperativeHandle} from "react";
import "./index.less";
import { useModel } from "umi";
import { dataMenu } from "./data"
import NotePage from "~/public/cpas-business/cpas-table/CpasNotes/index";
// import NotePage from "./page";

const Annotations = React.forwardRef((props: any, ref: any) => {
  const { initialState } = useModel('@@initialState');
  // const { dbname, zcbfid, zcbfName, sjnd, AuditReportTemplate } = initialState?.curPart as API.CurPart;
  const notePageRef = useRef<any>();
  const [isReady, setIsReady] = useState(false);
  
  useImperativeHandle(ref, () => ({
    notePageRef,
  }))

  useEffect(() => {
    // 延迟初始化，确保组件完全挂载后再渲染NotePage
    const timer = setTimeout(() => {
      setIsReady(true);
    }, 100);
    
    return () => clearTimeout(timer);
  }, []);

  // 添加安全检查，确保initialState和curPart存在
  if (!initialState || !initialState.curPart || !isReady) {
    return <div>加载中...</div>;
  }

  return (
   <div>
     <NotePage 
       ref={notePageRef} 
       initialState={initialState} 
       dbname={initialState?.curPart?.dbname} 
       dataMenu={dataMenu}
     />
   </div>
  );
})

export default Annotations;
